package com.lgk.mapper;

import com.lgk.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {
    /**
     * 获取全部用户
     * @return
     */
    @Select("select *from user")
    List<User> getAllUser() ;


    /**
     * 添加用户
     * @param user
     */
    @Insert("insert into user values(#{id},#{password},#{name},#{tell},#{time})")
    void addUser(User user);

    /**
     * id获取
     * @param id
     * @return
     */
    @Select("select *from user where id = #{id}")
    User getById(Integer id);

    /**
     * 修改用户
     * @param user
     */
    @Update("update user set password=#{password}, tell=#{tell} where id=#{id}")
    void updateUser(User user);

    /**
     * 删除用户
     * @param id
     */
    @Delete("delete from user where id = #{id}")
    void deleteUser(Integer id);

    /**
     * 登录
     * @param user
     * @return
     */
    @Select("select *from user where name = #{name} and password = #{password}")
    User getByUserNameAndPassword(User user);

    /**
     * 按用户名字模糊查询
     * @return
     */
    @Select("select *from user where name like concat('%',#{name},'%') ")
    List<User> getByNameAllUser(String name);

}
